home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-05-21 | 10.1 KB | 270 lines | [TEXT/ttxt] |
- --<<<-
- --*******************************************************************************
- --* Demo for: DigitalClock
- --* Required files: digtlclk.sx
- --* Author: Su Quek - Kaleida Labs, Inc.
- --*-----------------------------------------------------------------------------*
- --* Description: This script demonstrates how to create a digital clock/
- --* stopwatch.
- --* When you run "digtlclk.sxt", you should see a window
- --* with digital time display. Press the clock/stopwatch button
- --* to switch between the clock display and the stopwatch.
- --* Press the start/stop button and the reset button to start
- --* or stop and reset the stopwatch.
- --*******************************************************************************
-
- module DigitalClockModule
- uses ScriptX
- end
-
- in module DigitalClockModule
-
- --*=============================================================================*
- --* Set up DirReps
- --*=============================================================================*
- global mediaDir := spawn theScriptDir "media"
-
-
- --*=============================================================================*
- --* Load required files
- --*=============================================================================*
- -- Load Digital Clock
- fileIn theScriptDir name:"digtlclk.sx"
-
-
- --*=============================================================================*
- --* Define Demo
- --*=============================================================================*
- class Demo (Window)
- inst vars
- digitalClock
- end
-
- --*=============================================================================*
- --* Method name: importBitmap
- --* Class: Demo
- --* Usage: importBitmap self mediaDir bitmapFile
- --* mediaDir - DirRep
- --* bitmapFile - String object
- --*-----------------------------------------------------------------------------*
- --* Description: Imports the given bitmap from the given directory.
- --*=============================================================================*
- method importBitmap self {class Demo} mediaDir bitmapFile ->
- (
- local theStream := getStream mediaDir bitmapFile @readable
- local theColormap := importMedia theImportExportEngine theStream @image @dib @colormap
- local theBMP := importMedia theImportExportEngine theStream @image @dib @bitmap \
- colormap:theColormap --container:self.title
- return theBMP
- )
-
- --*=============================================================================*
- --* Method name: makeButtons
- --* Class: Demo
- --* Usage: makeButtons self
- --*-----------------------------------------------------------------------------*
- --* Description: Creates and lays out the start/stop button, the reset button
- --* and the clock/stopwatch button in the demo window.
- --*=============================================================================*
- method makeButtons self {class Demo} ->
- (
- --*=========================================================================*
- --* Create an actuator controller to control all the buttons in the demo
- --* window.
- --*=========================================================================*
- new ActuatorController space:self wholespace:true
-
- --*=========================================================================*
- --* Import all required bitmaps
- --*=========================================================================*
- local mediaDir := spawn theScriptDir "media"
- local clockBitmap := (importBitmap self mediaDir "clock.bmp")
- local stopwatchBitmap := (importBitmap self mediaDir "stopwtch.bmp")
- local resetRelBitmap := (importBitmap self mediaDir "resetrel.bmp")
- local resetPrsBitmap := (importBitmap self mediaDir "resetprs.bmp")
- local resetDisBitmap := (importBitmap self mediaDir "resetdis.bmp")
- local startBitmap := (importBitmap self mediaDir "start.bmp")
- local stopBitmap := (importBitmap self mediaDir "stop.bmp")
- local disabledBitmap := (importBitmap self mediaDir "startdis.bmp")
-
- --*=========================================================================*
- --* Create the start/stop button
- --*=========================================================================*
- object startToggle (Toggle)
- toggledOnPresenter : (new TwoDShape boundary:stopBitmap)
- toggledOffPresenter : (new TwoDShape boundary:startBitmap)
-
- -- **** BUG!!! ****
- -- Setting the disabled presenter of a toggle to a bitmap returns:
- -- ** Not yet implemented #<Generic Substrate:widthSetter>. (Unimplemented)
- -- disabledPresenter : (new TwoDShape boundary:disabledBitmap)
- settings
- x : 140
- y : 60
- enabled : false
- authordata : self.digitalClock
- activateAction : (authordata self toggledOn -> (
- if toggledOn then
- start authordata
- else
- stop authordata
- ))
- end
-
- --*=========================================================================*
- --* Create the reset button
- --*=========================================================================*
- object resetButton (PushButton)
- releasedPresenter : (new TwoDShape boundary:resetRelBitmap)
- pressedPresenter : (new TwoDShape boundary:resetPrsBitmap)
- disabledPresenter : (new TwoDShape boundary:resetDisBitmap)
- settings
- x : 140
- y : 85
- enabled : false
- authordata : self.digitalClock
- activateAction : (authordata self -> (
- reset authordata
- toggleOff startToggle
- ))
- end
-
- --*=========================================================================*
- --* Create the clock/stopwatch button
- --*=========================================================================*
- object clockToggle (Toggle)
- toggledOnPresenter : (new TwoDShape boundary:clockBitmap)
- toggledOffPresenter : (new TwoDShape boundary:stopwatchBitmap)
- settings
- x : 10
- y : 73
- authordata : self.digitalClock
- activateAction : (authordata self toggledOn -> (
- if toggledOn then
- (
- authordata.mode := @stopwatch
- startToggle.enabled := true
- resetButton.enabled := true
- )
- else
- (
- authordata.format := @12hour
- authordata.mode := @clock
- toggleOff startToggle
- startToggle.enabled := false
- resetButton.enabled := false
- )
- ))
- end
-
-
- --*=========================================================================*
- --* Append all buttons to the demo window
- --*=========================================================================*
- append self startToggle
- append self resetButton
- append self clockToggle
-
- return self
- )
-
- --*=============================================================================*
- --* Method name: makeDigitalClock
- --* Class: Demo
- --* Usage: makeDigitalClock self
- --*-----------------------------------------------------------------------------*
- --* Description: Creates and lays out the digital clock in the demo window.
- --*=============================================================================*
- method makeDigitalClock self {class Demo} ->
- (
- --*=========================================================================*
- --* Create a digital clock.
- --*=========================================================================*
- local dc := new DigitalClock boundary:(new rect x2:205 y2:50) \
- format:@12hour
- dc.position := new Point x:8 y:5
- dc.fill := blackBrush
- setDefaultAttr dc @brush (new Brush color:redColor)
- setDefaultAttr dc @font (new PlatFormFont name:"Times")
- setDefaultAttr dc @weight @bold
- setDefaultAttr dc @size 36
- setDefaultAttr dc @leading 36
- setDefaultAttr dc @alignment @center
-
- self.digitalClock := dc
-
- --*=========================================================================*
- --* Add digital clock to the demo window.
- --*=========================================================================*
- prepend self dc
-
- return self
- )
-
- --*=============================================================================*
- --* Method name: init
- --* Class: Demo
- --* Usage: init self
- --*-----------------------------------------------------------------------------*
- --* Description: Creates a 220x110 window.
- --*=============================================================================*
- method init self {class Demo} #rest args ->
- (
- apply nextMethod self boundary:(new Rect x2:220 y2:110) \
- centered:true \
- fill:(new Brush color:(new RGBColor red:200 green:200 blue:200)) \
- name:"Digital Clock" args
- return self
- )
-
- --*=============================================================================*
- --* Method name: afterInit
- --* Class: Demo
- --* Usage: afterInit self
- --*-----------------------------------------------------------------------------*
- --* Description: Calls methods to create the digital clock and buttons.
- --*=============================================================================*
- method afterInit self {class Demo} #rest args ->
- (
- makeDigitalClock self
- makeButtons self
-
- --*=========================================================================*
- --* Display the demo window
- --*=========================================================================*
- show self
-
- return self
- )
-
- --*=============================================================================*
- --* Create a title container
- --*=============================================================================*
- object tc (TitleContainer)
- dir : theScriptDir
- path : "digtlclk.sxt"
- name : "Digital Clock"
- end
-
- --*=============================================================================*
- --* Create demo
- --*=============================================================================*
- object win (Demo)
- title:tc
- end
-
- --*=============================================================================*
- --* Undefine global DirReps
- --*=============================================================================*
- mediaDir := undefined
-
- --*=============================================================================*
- --* Store module in the title container
- --*=============================================================================*
- append tc (getModule @DigitalClockModule)
- tc.startUpAction := (tc -> load tc[1]
- startClock win[1]
- show win)
- close tc
- -->>>
-